﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ParkingLot.Entitys.DbSessionEntitys;
using ParkingLot.Entitys.Enums;
using ParkingLot.Utility.Factory;

namespace ParkingLot.Utility.DBConnection
{
    /// <summary>
    /// 数据库会话接口
    /// </summary>
    public interface IDBSession: IDisposable
    {


        #region 命令



         int ExecuteCommand(DbSessionEntity dbSessionEntity, out string error);
        object ExecuteScalar(DbSessionEntity dbSessionEntity, out string error);

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
         DataTable GetDataTable(DbSessionEntity dbSessionEntity);


        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="dbSessionEntity">实体</param>
        /// <param name="con">连接</param>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
         DataTable GetDataTable(DbSessionEntity dbSessionEntity, SqlConnection con, out string error);

         DataTable ThreadGetDataTable(DbSessionEntity dbSessionEntity, SqlConnection con);


        /// <summary>
        /// 线程安全的查询表格方法
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
         DataTable ThreadGetDataTable(DbSessionEntity dbSessionEntity, out string error);


         DataTable ThreadGetDataTable(DbSessionEntity dbSessionEntity);
       

        #endregion

        #region 事务

        /// <summary>
        /// 开始事务
        /// </summary>
         void BeginTransaction();


        /// <summary>
        /// 提交事务
        /// </summary>
        /// <param name="error"></param>

        void Commit(out string error);


        /// <summary>
        /// 回滚
        /// </summary>
        /// <param name="error"></param>
        void RollBack(out string error);

        /// <summary>
        /// 提交事务
        /// </summary>
        void Commit();

        /// <summary>
        /// 回滚事物
        /// </summary>
        void RollBack();
        #endregion

         void Dispose();
    }

}
